/*
 * StringRecord.h
 *
 */

#ifndef STRINGRECORD_H_
#define STRINGRECORD_H_

#include <iostream>
#include "persistence/ISerializable.h"
#include "persistence/IEvaluator.h"

class StringRecord;

class ById : public IEvaluator<StringRecord> {
	private:
		BigInt id;
		friend class StringRecord;
	public:
		virtual ~ById() {}
		int eval(const StringRecord& record) const;
};

class ByValue : public IEvaluator<StringRecord> {
	private:
		String value;
		friend class StringRecord;
	public:
		virtual ~ByValue() {}
		int eval(const StringRecord& record) const;
};

class StringRecord : public ISerializable {
	private:
		static ById evalById;
		static ByValue evalByValue;

		BigInt id;
		String value;

	public:
		StringRecord();
		StringRecord(const StringRecord& copy);
		StringRecord(BigInt id, const String& value = "");
		StringRecord& operator=(const StringRecord& other);
		virtual ~StringRecord();

		BigInt getId() const;
		void setId(BigInt id);
		const String& getValue() const;
		void setValue(const String& value);

		BigInt size() const;
		void serialize(ISerializer& serializer) const;
		void unserialize(IUnserializer& unserializer);

		friend std::ostream& operator<< (std::ostream& stream, const StringRecord& record);

		static const ById& byId(BigInt id);
		static const ByValue& byValue(const String& value);

		static bool compByIdDesc(void* a, void* b);
		static bool compByValDesc(void* a, void* b);
};

#endif  /* STRINGRECORD_H_ */
